import {createRouter, createWebHashHistory} from "vue-router";
// import LoginPage from "../components/Login.vue";
// import HomePage from "../components/HomePage.vue";
import Store from "../tools/Storage";
// import OrderComp from "../components/Order.vue"
// import GoodsComp from "@/components/goods/Goods.vue";
// import GoodsCategory from "@/components/goods/GoodsCategory.vue";
// import DataCom from "@/components/DataCom.vue";


const Router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: "/",
            name: "index",
            redirect: {name: "homepage"}
        },
        {
            path: "/login",
            component: () => import("../components/Login.vue"),
            name: "login",
            props: true
        },
        {
            path: "/home",
            component: () => import("../components/HomePage.vue"),
            name: "homepage",
            children: [{
                path: 'order/:type',
                name: 'order',
                component: () => import("../components/Order"),
                props: true
            }, {
                path: "goods/:type",
                name: "goods",
                component: () => import("../components/goods/Goods.vue"),
                props: true
            }, {
                path: "goods/category",
                name: "goodsCategory",
                component: () => import("../components/goods/GoodsCategory.vue"),
                props: true
            }, {
                path: "data/",
                name: "data",
                component: () => import("../components/DataCom.vue")
            }],
            redirect: () => {
                return {name: "order", params: {type: 0}}
            },

        }
    ]
})
Router.beforeEach((from) => {
    let isLogin = Store.getters.isLogin;
    if (isLogin || from.name === "login") {
        return true
    } else {
        return {name: "login"}
    }
    // return true
})

export default Router;